<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">

	</head>

	<body>

		<div class="col-lg-12" id="detailAwardInfo">
			<ol class="breadcrumb">
				<li><i class="fa fa-home"></i>
					<a href="index.html">Home</a>
				</li>
				<li><i class=""></i>查看获奖信息</li>
			</ol>

			<div class="mcomment">
				<h3 class="page-header"><i class=""></i>查看获奖信息</h3>
				<!--获奖信息搜索-->
				<div class="row form-group">
					<div class="input-group container-fluid" style="width: 50%;">
						<span class="input-group-addon">
							<i class="fa fa-search"></i>
						</span>
						<input v-model="searchBox" type="text" class="form-control" placeholder="输入想要搜索获奖信息" />
						<span class="input-group-btn">
							<button   @click="searchType(searchBox)"  class="btn btn-default">搜索</button>
						</span>
					</div>
				</div>
				<!--比赛信息搜索结束-->

				<!--列表及操作-->
				<!--操作-->
				<div>
					<!--列表-->
					<div>
						<table class="table table-bordered table-hover table-responsive">
							<thead>
								<tr>
									<td>
										<strong>姓名</strong>
									</td>
									<td>
										<strong>获奖比赛名称</strong>
									</td>
									<!--<td>
										<strong>获奖等级</strong>
									</td>
									<td>
										<strong>获奖类型</strong>
									</td>-->
									<td>
										<strong>获奖时间</strong>
									</td>
									<td>
										<strong>颁奖单位</strong>
									</td>
									<td>
										<strong>操作</strong>
									</td>
								</tr>
							</thead>
							<tr v-for='AwardInfo in AwardInfos'>
								<td>{{AwardInfo.name}}</td>
								<td>{{AwardInfo.coName}}</td>
								<!--<td>{{AwardInfo.grade}}</td>
								<td>{{AwardInfo.awards}}</td>-->
								<td>{{AwardInfo.winningTime}}</td>
								<td>{{AwardInfo.company}}</td>
								<td>
									<button data-toggle="modal" data-target="#showAwardinfo" @click="copy(AwardInfo.wiId)" class="btn btn-success">查看</button>
									<button data-toggle="modal" data-target="#modifyAwardinfo" @click="copy(AwardInfo.wiId)" class="btn btn-warning">修改</button>
									<button @click="delete1(AwardInfo.wiId)" class="btn btn-danger">删除</button>
								</td>
							</tr>
						</table>
					</div>
					<!--列表结束-->

				</div>
				<!--列表及操作结束-->
				<!--分页导航-->
				<center>
					<ul class="pagination">
						<li>
							<a @click="getajax(1)">首页</a>
						</li>
						<li>
							<a @click="getajax(page-1)">上一页</a>
						</li>
						<li>
						<li v-for="value in showpage">
							<a style="background: red;" @click="getajax(value)" v-if="page==value">
								{{value}}
							</a>

							<a v-else @click="getajax(value)">{{value}}</a>

						</li>
						</li>
						<li>
							<a @click="getajax(page+1)">下一页</a>
						</li>
						<li>
							<a @click="getajax(countpage)">尾页</a>
						</li>
					</ul>
				</center>
				<!--分页导航结束-->
			</div>

			<!--查看弹出框 start-->
			<div class="modal" id="showAwardinfo">
				<div class="modal-dialog">
					<div class="modal-content" >
						<div class="modal-header">
							<button class="close" data-dismiss="modal">
							<span>&times;</span>
						</button>
							<h4>查看获奖信息</h4>
						</div>

						<div class="modal-body" id="detali">

								<table class="table table-bordered">

								<tr>

									<td><label for="awardPersonName">获奖人姓名：</label></td>
									<td><input v-model="copys.name" class="form-control " type="text" readonly="readonly" /></td>

								</tr>

								<tr>

									<td><label for="matchName">获奖比赛名称：</label></td>
									<td><input v-model="copys.coName" class="form-control " type="text" readonly="readonly" /></td>

								</tr>

								<tr>

									<td><label for="awardCompany">颁奖单位：</label></td>
									<td><input v-model="copys.company" class="form-control " type="text" readonly="readonly" /></td>


								</tr>

								<tr>
									<td><label for="awardLevel">获奖等级：</label></td>
									<td><input v-model="da.gradeName" class="form-control " type="text" readonly="readonly" /></td>

								</tr>

								<tr>
									<td><label for="awardType">获奖类型：</label></td>
									<td><input v-model="da.awardsName" class="form-control " type="text" readonly="readonly" /></td>

								</tr>

								<tr>
									<td><label for="awardTime">获奖时间：</label></td>
									<td><input v-model="copys.winningTime" class="form-control " type="text" readonly="readonly" /></td>

								</tr>

							</table>

							<div class="form-group">
								<label for="awardContent">获奖人介绍：</label>
								<!--<textarea disabled="disabled" class="form-control" id="noticeContent" cols="100%" rows="10">-->
												<!--{{copys.trend}}																				-->
									<!--</textarea>-->
								<div v-html="copys.trend"  class="form-control" style="width: 100%;height: 100%"></div>
							</div>
						</div>

					</div>
				</div>
			</div>

			<!--查看弹出框 end-->

			<!--修改弹出框 start-->
			<div class="modal" id="modifyAwardinfo">
				<div class="modal-dialog">
					<div class="modal-content" style="width: 800px">
						<div class="modal-header">
							<button class="close" data-dismiss="modal">
							<span>&times;</span>
										</button>
							<h4>修改获奖详情</h4>
						</div>

						<div class="modal-body">
							<table class="">
								<tr>

									<td><label for="awardPersonName">获奖人姓名：</label></td>
									<td><input v-model="copys.name" type="text" class="form-control" id="awardPersonName" placeholder="请输入获奖人姓名" /></td>

								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>
								<tr>

									<td><label for="matchName">获奖比赛名称：</label></td>
									<td><input v-model="copys.coName" type="text" class="form-control" id="matchName" placeholder="请输入获奖比赛名称" /></td>

								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>
								<tr>

									<td><label for="awardCompany">颁奖单位：</label></td>
									<td><input v-model="copys.company " type="text" class="form-control" id="awardCompany" placeholder="请输入颁奖单位名称" /></td>

								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>
								<tr>
									<td><label for="awardLevel">获奖等级：</label></td>
									<td>
										<select v-model="copys.grade" class="form-control" id="awardLevel">
											<option v-for="gr in grades" v-bind:value="gr.grade">
												{{gr.gradeName}}
											</option>
										</select>

									</td>
								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>
								<tr>
									<td><label for="awardType">获奖类型：</label></td>
									<td>
										<select v-model="copys.awards" class="form-control" id="awardType">
											<option v-for="aw in awardslist" v-bind:value="aw.awards">
												{{aw.awardsName}}
											</option>

										</select>
									</td>
								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>
								<tr>
									<td><label for="awardTime">获奖时间：</label></td>
									<td><input v-model="da.t1" type="date" class="form-control" id="awardTime" /></td>
								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>

								<tr>
									<td colspan="2">
										<div class="form-group">
											<label for="noticeContent">获奖人介绍：</label>
											<!--<textarea v-model="copys.trend" class="form-control" id="noticeContent" cols="100%" rows="10"></textarea>-->
											<textarea id="text1Modify"    class="form-control" style="display: none" >
											</textarea>
											<div id="meuenModify" class="toolbar">
											</div>
											<div style="padding: 5px 0; color: #ccc"></div>
											<div id="editorModify"   class="text" style="width: 100%;height: 100%;border:1px solid black"> <!--可使用 min-height 实现编辑区域自动增加高度-->

											</div>
										</div>
									</td>
								</tr>
								<tr>
									<td colspan="2">
										<center>
											<div style="width: 50%;">
												<button class="btn btn-default" @click="publish">发布</button>
												<button class="btn btn-danger" data-dismiss="modal">取消</button>
											</div>
										</center>
									</td>
								</tr>

							</table>

						</div>

					</div>
				</div>
			</div>

			<!--修改弹出框 end-->

		</div>

		<script type="text/javascript">
			//			var url1 = 'http://donting.vipgz1.idcfengye.com';
			var url1 = 'http://donting.free.idcfengye.com';
			var editor;
			var da = new Vue({
				el: '#detailAwardInfo',
				data: {
					count: '', //总记录数
					countpage: '10', //总页数
					page: '1', //当前页
					showpage: [],
					AwardInfos: [], //所有数据
					searchBox: '', //搜索输入框

					copys: {}, //查看获奖详情

					grade: '', //获奖等级
					awards: '', //获奖类型

//					gradeName: '',
//					awardsName: '',
					//拆分日期		
					t1: '',

					//获奖等级列表
					grades: [{
							grade: '1',
							gradeName: '一等奖'
						},
						{
							grade: '2',
							gradeName: '二等奖'
						},
						{
							grade: '3',
							gradeName: '三等奖'
						},
						{
							grade: '1',
							gradeName: '优秀奖'
						},
					],
					//					获奖类型列表
					awardslist: [{
							awards: '1',
							awardsName: '校级'
						},
						{
							awards: '2',
							awardsName: '市级'
						},
						{
							awards: '3',
							awardsName: '省/部级'
						},
						{
							awards: '4',
							awardsName: '国家级'
						},

					],

				},
				methods: {
					copy: function(wiId) {
						console.log(wiId);
						for(var i = 0; i < da.AwardInfos.length; i++) {
							if(wiId == da.AwardInfos[i].wiId) {

								da.copys = da.AwardInfos[i];
								da.t1 = da.AwardInfos[i].winningTime.split(" ")[0];
								console.log(da.t1 + "-----");

								for(var j = 0; j < da.grades.length; j++) {
									if(da.copys.grade == da.grades[j].grade) {
										da.gradeName = da.grades[j].gradeName;
										console.log(da.gradeName + "----da.gradeName")
										for(var t = 0; t < da.awardslist.length; t++) {
											if(da.copys.awards == da.awardslist[t].awards) {
												da.awardsName = da.awardslist[t].awardsName;

												editor.txt.html(da.copys.trend);

												return;
											}
										}
									}
								}

								return;
							}
						}
					},

					delete1: function(id) {
						console.log(id);
						axios.defaults.withCredentials = true;
						let wiId = id;
						axios.get(url1 + '/winning/delete', {　
							params: {
								'wiId': wiId
							}
						}).then(function(response) {
							var rs = response.data;
							alert(rs.code);
							if(rs.code == 200) {

								alert("删除成功!");
								da.getajax(da.page);
							} else {
								alert("删除失败!");
							}

						}).catch(function(error) {　　
							alert("连接超时！");
						});

					},

					searchType: function(searchBox) {
						alert(searchBox);
					},
					publish: function() {
						var x=document.getElementById("text1Modify");

						da.copys.trend=x.value;
						axios.defaults.withCredentials = true;

						axios.post(url1 + '/winning/modify', {

								'name': da.copys.name,
								'company': da.copys.company,
								'coName': da.copys.coName,
								'grade': da.copys.grade,
								'awards': da.copys.awards,
								'winningTime': da.copys.winningTime,
								'trend': da.copys.trend,
								'wiId': da.copys.wiId

						}).then(function(response) {
							var rs = response.data;

							alert(rs.code);　　
							if(rs.code == 200) {
								da.getajax(da.page);
								alert("修改成功!");
							} else {
								alert("修改失败!");
							}

						}).catch(function(error) {　　
							alert("连接超时！");
						});

					},

					getajax: function(page1) {
						if(page1 <= 0) {
							alert("没有上一页");
							return;
						}
						if(page1 > this.countpage) {
							alert("没有下一页了");
							return;
						}

						axios.defaults.withCredentials = true;

						axios.get(url1 + '/winning/findAllPage', {
							params: {
								'page': page1
							}
						}).then(function(response) {
							var rs = response.data;　

							if(rs.code !=200) {
								alert("无数据");
								return;
							}

							da.countpage = rs.countpage;
							da.page = rs.page;
							da.count = rs.count;
							da.AwardInfos = rs.data;
							var cout = 0;
							var pa = [];
							if (rs.page <= 3) {

								for (var i = 1; i <= da.countpage && cout < 5; i++) {
									pa.push(i);
									cout++;
								}

							} else {

								if (rs.countpage - rs.page >= 2) {
									pa.push(rs.page - 2);
									pa.push(rs.page - 1);
									pa.push(rs.page);
									pa.push(rs.page + 1);
									pa.push(rs.page + 2);
								} else {
									pa.push(rs.countpage - 4);
									pa.push(rs.countpage - 3);
									pa.push(rs.countpage - 2);
									pa.push(rs.countpage - 1);
									pa.push(rs.countpage);

								}

							}
							da.showpage = pa;

						}).catch(function(error) {　　
							alert("连接超时！");
						});

					}

				},
				mounted() {
					this.getajax(1);

					var E = window.wangEditor

					editor =new E('#meuenModify', '#editorModify');
					var $text1 = $('#text1Modify')
					editor.customConfig.withCredentials = true
					editor.customConfig.uploadFileName = 'file';
					editor.customConfig.uploadImgServer = url1+'/addEdImgUp'

					editor.customConfig.onchange = function (html) {
						// 监控变化，同步更新到 textarea
						$text1.val(html)
						console.log("更新...")
					}

					editor.create()
				}

			})
		</script>

	</body>

</html>